package com.diankangwo.controller;


import com.diankangwo.constant.resultMsg;
import com.diankangwo.dao.TypeDAO;
import com.diankangwo.domain.Type;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 一级分类控制器
 */
@Controller
@Api(description = "一级分类")
public class TypeController {

    @Autowired
    private TypeDAO typeDao;

    /**
     * 获取所有一级分类
     * @return json
     */
    @ApiOperation(value="获取所有一级分类", notes="")
    @ResponseBody
    @RequestMapping(value = "/type/list", method = RequestMethod.GET)
    public String show() {
        List<Type> typesList = typeDao.findAll();
        String code = "1";
        String msg = "处理异常！";
        if (typesList != null) {
            msg = "查询成功！";
        }else {
            msg = "未查询到分类信息！";
        }
        return resultMsg.mapToJson(code, msg, typesList);
    }
}
